package com.ruibang.glass.purchase.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruibang.glass.purchase.domain.req.PurchaseSupplierReq;
import com.ruibang.glass.purchase.entity.ProcureSupplierManagement;
import com.ruibang.glass.purchase.service.ProcureSupplierManagementService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author mameng
 * 供应商管理
 */
@Api(tags = "供应商管理")
@RestController
@RequestMapping("/api/glass/purchase/supplier/management")
public class PurchaseSupplierManagementController {


    @Autowired
    private ProcureSupplierManagementService procureSupplierManagementService;

    @PostMapping("/list")
    @ApiOperation(value = "供应商列表", response = ResultBody.class)
    public ResultBody queryList(@RequestBody PurchaseSupplierReq purchaseSupplierReq) {
        return ResultBody.success(procureSupplierManagementService.getPage(purchaseSupplierReq));
    }

    @PostMapping("/add")
    @ApiOperation(value = "供应商列表", response = ResultBody.class)
    public ResultBody addSupplier(@RequestBody ProcureSupplierManagement procureSupplierManagement) {
        procureSupplierManagementService.addSupplier(procureSupplierManagement);
        return ResultBody.success();
    }


    @PostMapping("/chooseDelete")
    @ApiOperation(value = "选中删除", response = ResultBody.class)
    public ResultBody chooseDelete(@RequestBody ProcureSupplierManagement procureSupplierManagement) {
        procureSupplierManagementService.removeBatchByIds(procureSupplierManagement.getIds());
        return ResultBody.success();
    }


    @PostMapping("/updateSupplier")
    @ApiOperation(value = "修改供应商", response = ResultBody.class)
    public ResultBody updateSupplier(@RequestBody ProcureSupplierManagement procureSupplierManagement) {
        procureSupplierManagementService.updateById(procureSupplierManagement);
        return ResultBody.success();
    }

    @GetMapping("/getSupplierList")
    @ApiOperation(value = "提供供应商下拉框", response = ResultBody.class)
    public ResultBody getSupplierList() {
        return ResultBody.success(procureSupplierManagementService.list(
                Wrappers.<ProcureSupplierManagement>lambdaQuery()
                        .select(ProcureSupplierManagement::getId,
                                ProcureSupplierManagement::getSupplierName,
                                ProcureSupplierManagement::getSupplierCode,
                                ProcureSupplierManagement::getEmail,
                                ProcureSupplierManagement::getAddress,
                                ProcureSupplierManagement::getLegalRepresentative,
                                ProcureSupplierManagement::getContactPerson,
                                ProcureSupplierManagement::getMobilePhone)
        ));
    }


}
